package pers.cj.pdos.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import pers.cj.pdos.cache.CacheData;
import pers.cj.pdos.cache.CacheRemove;
import pers.cj.pdos.cache.CacheRemoveMore;
import pers.cj.pdos.constant.OrderType;
import pers.cj.pdos.entity.Store;
import pers.cj.pdos.mapper.OrderRuleMapper;
import pers.cj.pdos.mapper.StoreMapper;
import pers.cj.pdos.service.IStoreService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import pers.cj.pdos.utils.Utils;
import pers.cj.pdos.vo.HouseVo;
import pers.cj.pdos.vo.StoreVo;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author chenj
 * @since 2019-11-04
 */
@Service
public class StoreServiceImpl extends ServiceImpl<StoreMapper, Store> implements IStoreService {
    @Autowired
    private StoreMapper storeMapper;
    @Autowired
    OrderRuleMapper orderRuleMapper;


    @Override
    public List<Store> list(String companyId) {
        return storeMapper.selectList(new QueryWrapper<Store>().eq("company_id",companyId));
    }

    @Override
    public List<StoreVo> listVoPage(Integer page, Integer limit, String companyId, String searchContent) {
        return storeMapper.listVo(Utils.genPage(page,limit),limit,companyId, Utils.genLikeData(searchContent));
    }

    @Override
    public long count(String companyId, String searchContent) {
        return storeMapper.count(companyId,Utils.genLikeData(searchContent));
    }

    @Override
    public boolean checkName(String name, String companyId) {
        return storeMapper.selectCount(new QueryWrapper<Store>().eq("company_id",companyId).eq("name",name)) > 0;
    }

    @Override
    public boolean checkNo(String no, String companyId) {
        return storeMapper.selectCount(new QueryWrapper<Store>().eq("company_id",companyId).eq("no",no)) > 0;
    }

    @Override
    public StoreVo getVoById(String id) {
        return storeMapper.getVoById(id,null);
    }

    @Override
    public StoreVo getVoByIdAndHouseNormal(String id) {
        return storeMapper.getVoById(id,1);
    }

    @Override
    public void update(Store store) {
        storeMapper.updateById(store);
    }

    @Override
    public void remove(Store store) {
        storeMapper.deleteById(store.getId());
    }

    @Override
    public void insert(Store store) {
        storeMapper.insert(store);
//        orderRuleMapper.addOrderRuleCurrent(store.getCompanyId(), OrderType.MD.getType());
    }
}
